package com.ruoyi.wechat.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wechat.domain.Facility;
import com.ruoyi.wechat.domain.FacilityType;
import com.ruoyi.wechat.domain.WxCampFacilityVo;
import com.ruoyi.wechat.service.IWxFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat/facility")
public class WxFacilityController extends BaseController {

    @Autowired
    private IWxFacilityService wxFacilityService;
    /**
     * 获取服务设施类型以及对应的服务设施数据列表
     */
    @GetMapping("/wxlist")
    public AjaxResult list(){
        List<FacilityType> list = wxFacilityService.facilityTypeList();
        return success(list);
    }
    /**
     * 根据营地Id和服务设施Id集合完成批量添加
     */
    @PostMapping("/wxadd")
    public AjaxResult add(@RequestBody WxCampFacilityVo wxCampFacilityVo){
        if (wxCampFacilityVo.getCampId() == null){
            return error("营地Id不能为空");
        }
        return toAjax(wxFacilityService.insertCampFacility(wxCampFacilityVo.getCampId(),
                wxCampFacilityVo.getFacilityIds()));
    }
    /**
     * 根据营地Id查询营地的服务设施列表
     */
    @GetMapping("/wxgetInfo/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId){
        if(campId == null){
            return  error("营地Id不能为空");
        }
        List<FacilityType> list = wxFacilityService.campFacilityListByCampId(campId);
        return success(list);
    }
    /**
     * 根据营地Id完成删除
     * @return
     */
    @DeleteMapping("/wxdelete/{campId}")
    public AjaxResult delete(@PathVariable("campId") String campId){
        if(campId == null){
            return  error("营地Id不能为空");
        }
        return toAjax(wxFacilityService.deleteCampFacilityByCampId(campId));
    }
}
